package com.ear.orange.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ear.orange.common.BaseContext;
import com.ear.orange.common.Result;
import com.ear.orange.entity.User;
import com.ear.orange.mapper.UserMapper;
import com.ear.orange.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author orange
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Result editUserInfo(User user) {
        Boolean edit = userMapper.editUserInfo(user);
        if (edit) {
            return this.getUserInfo();
        }
        return Result.error(Result.UPDATE_ERROR);
    }

    @Override
    public Result getUserInfo() {
        Long userId = BaseContext.getCurrentId();
        User user = userMapper.getUserInfoById(userId);
        return Result.success(Result.SELECT_SUCCESS + ",用户信息:", user);
    }
}
